﻿BORDER_TEXTURE			= "Interface\\AddOns\\eMap\\Textures\\border"
BLANK_TEXTURE			= "Interface\\AddOns\\eMap\\Textures\\blank"
glowTex 				= "Interface\\AddOns\\eMedia\\glowTex"

--------------------------------------------------------------------
-- MINIMAP CONFIG
--------------------------------------------------------------------

local scale = 0.92857143
local position = "TOPLEFT"
local position_x = 20
local position_y = -20

--------------------------------------------------------------------
-- MINIMAP CONFIG
--------------------------------------------------------------------

--------------------------------------------------------------------
-- MINIMAP BORDER
--------------------------------------------------------------------

	local Panel = CreateFrame("Frame", mapborder, Minimap)
	Panel:SetFrameLevel(0)
	Panel:SetFrameStrata("background")
	Panel:SetPoint("LEFT", Minimap, "LEFT", 0, 0)
	Panel:SetPoint("RIGHT", Minimap, "RIGHT", 0, 0)
	Panel:SetPoint("TOP", Minimap, "TOP", 0, 0)
	Panel:SetPoint("BOTTOM", Minimap, "BOTTOM", 0, 0)
	Panel:SetScale(1)
	
	Panel:SetBackdrop( { 
	  bgFile = BLANK_TEXTURE, 
	  edgeFile = BLANK_TEXTURE, 
	  tile = false, tileSize = 0, edgeSize = 1, 
	  insets = { left = -1, right = -1, top = -1, bottom = -1 }
	})
	Panel:SetBackdropColor(0.1,0.1,0.1,1)
	Panel:SetBackdropBorderColor(0.1,0.1,0.1,1)
	Panel:Show()
	
	local FrameBackdrop = CreateFrame("Frame", mapborder, Panel)
	FrameBackdrop:SetFrameLevel(0)
	FrameBackdrop:SetFrameStrata("background")
	FrameBackdrop:SetHeight(134)
	FrameBackdrop:SetAlpha(0.8)
	FrameBackdrop:SetPoint("LEFT", Panel, "LEFT", -5, 0)
	FrameBackdrop:SetPoint("RIGHT", Panel, "RIGHT", 5, 0)
	FrameBackdrop:SetPoint("TOP", Panel, "TOP", 0, 5)
	FrameBackdrop:SetPoint("BOTTOM", Panel, "BOTTOM", 0, -5)
	FrameBackdrop:SetFrameStrata("BACKGROUND")
	FrameBackdrop:SetBackdrop {
	  edgeFile = glowTex, edgeSize = 5,
	  insets = {left = 3, right = 3, top = 3, bottom = 3}
	}
	FrameBackdrop:SetBackdropColor(0, 0, 0, 0)
	FrameBackdrop:SetBackdropBorderColor(0, 0, 0)
--------------------------------------------------------------------
-- MINIMAP ROUND TO SQUARE AND MINIMAP SETTING
--------------------------------------------------------------------

Minimap:SetScale(scale)
Minimap:SetFrameStrata("BACKGROUND")
Minimap:ClearAllPoints()
Minimap:SetPoint(position, UIParent, position_x, position_y)	

local function kill() end

-- Hide Border
MinimapBorder:Hide()
MinimapBorderTop:Hide()


-- Hide Zoom Buttons
MinimapZoomIn:Hide()
MinimapZoomOut:Hide()

-- Hide Voice Chat Frame
MiniMapVoiceChatFrame:Hide()
MiniMapVoiceChatFrame:UnregisterAllEvents()
MiniMapVoiceChatFrame.Show = kill

-- Hide Game Time
GameTimeFrame:Hide()

-- 小地图位置
MinimapZoneTextButton:SetParent("Minimap")
MinimapZoneTextButton:SetPoint("TOP", Minimap, "TOP", 0, 10)	--where the zone text is located
MinimapZoneTextButton:SetFrameLevel(5)
MinimapZoneText:SetFont(STANDARD_TEXT_FONT, 13, "OUTLINE")	--font and font size for zone text
--MinimapZoneTextButton:Hide()
--MinimapZoneTextButton:UnregisterAllEvents()

-- Hide Minimap Toggle
MinimapToggleButton:Hide()
MinimapToggleButton:UnregisterAllEvents()

-- Hide Tracking Button
MiniMapTracking:Hide()
MiniMapTracking:UnregisterAllEvents()

-- Hide Mail Button
MiniMapMailFrame:ClearAllPoints()
MiniMapMailFrame:SetPoint("TOPRIGHT", Minimap, 3, 4)
MiniMapMailBorder:Hide()
MiniMapMailIcon:SetTexture("Interface\\AddOns\\eMap\\Textures\\mail")

-- Move battleground icon
BattlegroundShine:Hide()
MiniMapBattlefieldBorder:SetTexture('')
MiniMapBattlefieldFrame:ClearAllPoints()
MiniMapBattlefieldFrame:SetPoint("BOTTOMRIGHT", Minimap, 5, -5)




-- Hide North tag
MinimapNorthTag.Show = kill
MinimapNorthTag:Hide()

-- Hide world map button
MiniMapWorldMapButton:Hide()
MiniMapWorldMapButton:UnregisterAllEvents()

-- Enable mouse scrolling
Minimap:EnableMouseWheel(true)
Minimap:SetScript("OnMouseWheel", function(self, d)
	if d > 0 then
		_G.MinimapZoomIn:Click()
	elseif d < 0 then
		_G.MinimapZoomOut:Click()
	end
end)

Minimap:SetScript("OnMouseUp", function(self, btn)
	if btn == "RightButton" then
		ToggleDropDownMenu(1, nil, MiniMapTrackingDropDown, self)
	elseif btn == "MiddleButton" then
		GameTimeFrame:Click() 
	else
		Minimap_OnClick(self)
	end
end)

-- Set Square Map Mask
Minimap:SetMaskTexture("Interface\\AddOns\\eMap\\Textures\\Mask.blp")

-------------------------------------------------------------------
-- MAP
-------------------------------------------------------------------

Addon = CreateFrame("Frame")

-- Player Text Object
local Player = WorldMapButton:CreateFontString(nil, "ARTWORK")
Player:SetPoint("BOTTOM", WorldMapButton, -50, -21)
Player:SetFontObject("GameFontNormal")
Player:SetTextColor(1, 1, 1)

-- Divider
local Divider = WorldMapButton:CreateFontString(nil, "ARTWORK")
Divider:SetPoint("BOTTOM", WorldMapButton, 0, -21)
Divider:SetFontObject("GameFontNormal")
Divider:SetTextColor(1, 1, 1)
Divider:SetText("|")

-- Cursor Text Object
local Cursor = WorldMapButton:CreateFontString(nil, "ARTWORK")
Cursor:SetPoint("BOTTOM", WorldMapButton, 50, -21)
Cursor:SetFontObject("GameFontNormal")
Cursor:SetTextColor(1, 1, 1)

WorldMapButton:HookScript("OnUpdate", function(self, u)
	-- Player Position
	local PlayerX, PlayerY = GetPlayerMapPosition("player")
	local mult = 10^1
	PlayerX = math.floor(PlayerX*100*mult+0.5)/mult
	PlayerY = math.floor(PlayerY*100*mult+0.5)/mult
	Player:SetText(PlayerX.." - "..PlayerY)
	
	-- Cursor Position
	local cX, cY = WorldMapDetailFrame:GetCenter()
	local CursorX, CursorY = GetCursorPosition()
	CursorX = math.floor((((CursorX/WorldMapFrame:GetScale())-(cX-(WorldMapDetailFrame:GetWidth()/2)))/10)*mult+.05)/mult
	CursorY = math.floor(((((cY+(WorldMapDetailFrame:GetHeight()/2))-(CursorY/WorldMapFrame:GetScale()))/WorldMapDetailFrame:GetHeight())*100)*mult+.05)/mult
	
	if CursorX >= 100 or CursorY >= 100 or CursorX <= 0 or CursorY <= 0 then
		Cursor:SetText("0 . 0")
	else
		Cursor:SetText(CursorX.." - "..CursorY)
	end
end)


WorldMapFrame:EnableKeyboard(false)
WorldMapFrame:EnableMouse(false)
BlackoutWorld:Hide()
UIPanelWindows["WorldMapFrame"] = {area = "center"}
WorldMapFrame:HookScript("OnShow", function(self) self:SetScale(0.7) end)

Addon:SetScript("OnEvent", UpdateParty)



	
